package testcases;

import base.BaseTest;
import base.JsonAssertion;
import constants.Owner;
import config.ApiPath;
import org.testng.annotations.Test;
import lombok.extern.slf4j.Slf4j;
import utils.GeneralUtils;

import java.util.List;


@Slf4j
public class ExampleTest extends BaseTest {

    @Test(testName="get-yamlDrive-通过注解加载yaml-手动断言", groups= {Owner.Linbenjie})
    @ApiPath("caseData/demo/user-get-demo.yaml")
    public void testYamlDriveGet() {
        String res = yamlDrive();
        log.info("res:{}", res);
        JsonAssertion jsonAssertion = new JsonAssertion(res);
        jsonAssertion.assertEquals("$.user.age", "15");
    }

    @Test(testName="yamlDriveAssert-通过注解加载yaml-请求-自动断言", groups= {Owner.Linbenjie})
    @ApiPath("caseData/demo/user-post-demo.yaml")
    public void testYamlDriveAssert() {
        yamlDriveAssert();
    }

    @Test(testName="post-yamlDrive-通过注解加载yaml-手动断言", groups= {Owner.Linbenjie})
    @ApiPath("caseData/demo/post-demo.yaml")
    public void testYamlDrive() {
        // 设置当前测试用例的变量
        setTestCaseVariable("post-demo-id", "1");

        String res = yamlDrive();
        log.info("res:{}", res);
        JsonAssertion jsonAssertion = new JsonAssertion(res);
        jsonAssertion.assertEquals("$.idList", "[ \"123\", \"567\" ]");
    }


    @Test(testName="yamlDrive-通过注解加载多个请求的yaml-手动断言", groups= {Owner.Linbenjie})
    @ApiPath("caseData/demo/multi_request.yaml")
    public void testYamlDriveMulti() {
        // 设置当前测试用例的变量
        setTestCaseVariable("USER_ID1", "1");
        setTestCaseVariable("USER_ID2", "2");

        List<String> responses = yamlDriveMulti();
        for (String res : responses) {
            log.info("res:{}", res);
            JsonAssertion jsonAssertion = new JsonAssertion(res);
            jsonAssertion.assertEquals("$.code", "1000");
        }

    }

    @Test(testName="yamlDriveAssertMulti-通过注解加载多个请求的yaml-请求-断言", groups= {Owner.Linbenjie})
    @ApiPath("caseData/demo/multi_request.yaml")
    public void testYamlDriveAssertMulti() {
        // 设置当前测试用例的变量
        setTestCaseVariable("USER_ID1", "1");
        setTestCaseVariable("USER_ID2", "2");

        yamlDriveAssertMulti();
    }



}